﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace weixin
{
    /// <summary>
    /// wxvalidate 的摘要说明
    /// </summary>
    public class wxvalidate : IHttpHandler
    {

        private string token = "jmsoeasy";
        private weixin.api.WXApiFunction wx = new api.WXApiFunction();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request.HttpMethod.ToUpper() == "POST")
            {
                try
                {
                    wx.RequestMsg();
                }
                catch (Exception ex)
                {
                    weixin.api.WXComm.WriteLog("报错了---" + ex.Message + "--" + ex.Source + "--" + ex.StackTrace);
                }
            }
            else
            {
                string echoStr = context.Request.QueryString["echoStr"];
                if (wx.CheckSignature(token))
                {
                    if (!string.IsNullOrEmpty(echoStr))
                    {
                        context.Response.Write(echoStr);
                        context.Response.End();
                    }
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}